package com.shuyu.gsyvideoplayer.player;

import android.content.Context;
import android.media.PlaybackParams;
import android.net.Uri;
import android.os.Build;
import android.os.Message;
import android.view.Surface;
import com.shuyu.gsyvideoplayer.cache.ICacheManager;
import com.shuyu.gsyvideoplayer.model.GSYModel;
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import java.util.List;
import tv.danmaku.ijk.media.player.AndroidMediaPlayer;
import tv.danmaku.ijk.media.player.IMediaPlayer;

/* loaded from: classes.dex */
public class SystemPlayerManager implements IPlayerManager {
    private AndroidMediaPlayer mediaPlayer;
    private boolean release;
    private Surface surface;

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getBufferedPercentage() {
        return -1;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public boolean isSurfaceSupportLockCanvas() {
        return false;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setSpeedPlaying(float f, boolean z) {
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public IMediaPlayer getMediaPlayer() {
        return this.mediaPlayer;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void initVideoPlayer(Context context, Message message, List<VideoOptionModel> list, ICacheManager iCacheManager) {
        this.mediaPlayer = new AndroidMediaPlayer();
        this.mediaPlayer.setAudioStreamType(3);
        this.release = false;
        GSYModel gSYModel = (GSYModel) message.obj;
        try {
            if (gSYModel.isCache() && iCacheManager != null) {
                iCacheManager.doCacheLogic(context, this.mediaPlayer, gSYModel.getUrl(), gSYModel.getMapHeadData(), gSYModel.getCachePath());
            } else {
                this.mediaPlayer.setDataSource(context, Uri.parse(gSYModel.getUrl()), gSYModel.getMapHeadData());
            }
            this.mediaPlayer.setLooping(gSYModel.isLooping());
            if (gSYModel.getSpeed() == 1.0f || gSYModel.getSpeed() <= 0.0f) {
                return;
            }
            setSpeed(gSYModel.getSpeed());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void showDisplay(Message message) {
        AndroidMediaPlayer androidMediaPlayer;
        if (message.obj == null && (androidMediaPlayer = this.mediaPlayer) != null && !this.release) {
            androidMediaPlayer.setSurface(null);
        } else if (message.obj != null) {
            Surface surface = (Surface) message.obj;
            this.surface = surface;
            if (this.mediaPlayer == null || !surface.isValid() || this.release) {
                return;
            }
            this.mediaPlayer.setSurface(surface);
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setSpeed(float f, boolean z) {
        setSpeed(f);
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setNeedMute(boolean z) {
        try {
            if (this.mediaPlayer != null && !this.release) {
                if (z) {
                    this.mediaPlayer.setVolume(0.0f, 0.0f);
                } else {
                    this.mediaPlayer.setVolume(1.0f, 1.0f);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void releaseSurface() {
        Surface surface = this.surface;
        if (surface != null) {
            surface.release();
            this.surface = null;
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void release() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            this.release = true;
            androidMediaPlayer.release();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getNetSpeed() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void start() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            androidMediaPlayer.start();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void stop() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            androidMediaPlayer.stop();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void pause() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            androidMediaPlayer.pause();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoWidth() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getVideoWidth();
        }
        return 0;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoHeight() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getVideoHeight();
        }
        return 0;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public boolean isPlaying() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.isPlaying();
        }
        return false;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void seekTo(long j) {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            androidMediaPlayer.seekTo(j);
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getCurrentPosition() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getCurrentPosition();
        }
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getDuration() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getDuration();
        }
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoSarNum() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getVideoSarNum();
        }
        return 1;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoSarDen() {
        AndroidMediaPlayer androidMediaPlayer = this.mediaPlayer;
        if (androidMediaPlayer != null) {
            return androidMediaPlayer.getVideoSarDen();
        }
        return 1;
    }

    private void setSpeed(float f) {
        AndroidMediaPlayer androidMediaPlayer;
        if (this.release || (androidMediaPlayer = this.mediaPlayer) == null || androidMediaPlayer.getInternalMediaPlayer() == null || !this.mediaPlayer.isPlayable()) {
            return;
        }
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                PlaybackParams playbackParams = new PlaybackParams();
                playbackParams.setSpeed(f);
                this.mediaPlayer.getInternalMediaPlayer().setPlaybackParams(playbackParams);
            } else {
                Debuger.printfError(" not support setSpeed");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
